import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:magic_car/user/login.dart';
import 'package:magic_car/main.dart';
import 'package:magic_car/util/HttpHelper.dart';
import 'package:magic_car/util/colors.dart';
import 'package:shared_preferences/shared_preferences.dart';

class StartPage extends StatefulWidget {
  StartPage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<StartPage> {
  GlobalKey globalKey = GlobalKey();
  Widget build(BuildContext context) {
    return new MaterialApp(
        title: '个人中心',
        debugShowCheckedModeBanner: false,
        home: new Scaffold(
            backgroundColor: Colors.white,
            appBar: new AppBar(
                title: new Text(
                  '',
                  style: TextStyle(color: Colors.black),
                ),
                backgroundColor: Colors.white,
                elevation: 0),
            body:

                //     SingleChildScrollView(
                //       scrollDirection: Axis.vertical,
                // //true 滑动到底部
                // reverse: false,
                // padding: EdgeInsets.all(0.0),
                // physics: BouncingScrollPhysics(),
                // child:
                RepaintBoundary(
                    key: globalKey,
                    child: ConstrainedBox(
                        constraints: BoxConstraints.expand(),
                        child: Stack(
                            alignment: Alignment.center, //指定未定位或部分定位widget的对齐方式
                            children: <Widget>[
                              Positioned(
                                top: 0,
                                left: 0,
                                right: 0,

                                // child:
                                // Center(
                                child: new Container(
                                    // color: Color.fromRGBO(255, 204, 48, 1),
                                    height: 50,
                                    // width: double.infinity,
                                    child: Padding(
                                      padding:
                                          new EdgeInsets.fromLTRB(0, 20, 0, 0),
                                      child: Center(
                                        child: Text(
                                          '你好',
                                          style: TextStyle(
                                            fontWeight: FontWeight.w600,
                                            fontSize: 20,
                                            // color: Color.fromRGBO(
                                            //     102, 102, 102, 1)
                                          ),
                                        ),
                                      ),
                                    )),
                              ),
                              Positioned(
                                top: 50,
                                left: 0,
                                right: 0,

                                // child:
                                // Center(
                                child: new Container(
                                    // color: Color.fromRGBO(255, 204, 48, 1),
                                    height: 50,
                                    // width: double.infinity,
                                    child: Padding(
                                      padding:
                                          new EdgeInsets.fromLTRB(0, 0, 0, 0),
                                      child: Center(
                                        child: Text(
                                          '欢迎使用车魔估',
                                          style: TextStyle(
                                            fontWeight: FontWeight.w600,
                                            fontSize: 20,
                                            // color: Color.fromRGBO(
                                            //     102, 102, 102, 1)
                                          ),
                                        ),
                                      ),
                                    )),
                              ),
                              Positioned(
                                top: 110,
                                left: 0,
                                right: 0,

                                // child:
                                // Center(
                                child: new Container(
                                    // color: Color.fromRGBO(255, 204, 48, 1),
                                    height: 100,
                                    // width: double.infinity,
                                    child: Padding(
                                      padding:
                                          new EdgeInsets.fromLTRB(0, 0, 0, 0),
                                      child: Center(
                                          child: new Image.asset(
                                              'resource/images/user/logo2.png')),
                                    )),
                              ),
                              Positioned(
                                  top: 250,
                                  left: 30,
                                  right: 30,

                                  // child:
                                  // Center(
                                  child: new Container(
                                    // color: Color.fromRGBO(255, 204, 48, 1),
                                    height: 50,
                                    // width: double.infinity,
                                    child: Padding(
                                        padding:
                                            new EdgeInsets.fromLTRB(0, 0, 0, 0),
                                        child: Center(
                                            child: SizedBox(
                                          width: double.infinity,
                                          child: new ClipRRect(
                                            borderRadius:
                                                BorderRadius.circular(25),
                                            child: Container(
                                              height: 50,
                                              // color: Color.fromRGBO(27, 182, 251, 1),
                                              child: new RaisedButton(
                                                child: Text('我是检测师',
                                                    style: TextStyle(
                                                      fontSize: 18,
                                                      color: Colors.white,
                                                    )),
                                                //color: Colors.red,
                                                onPressed: () async {
                                                  // BuildContext buildContext =
                                                  //     globalKey.currentContext;
                                                  // if (null != buildContext) {
                                                  //   RenderRepaintBoundary
                                                  //       boundary = buildContext
                                                  //           .findRenderObject();
                                                  //   ui.Image image =
                                                  //       await boundary
                                                  //           .toImage();
                                                  //   ByteData byteData =
                                                  //       await image.toByteData(
                                                  //           format: ui
                                                  //               .ImageByteFormat
                                                  //               .png);
                                                  //   final result =
                                                  //       await ImageGallerySaver
                                                  //           .saveImage(byteData
                                                  //               .buffer
                                                  //               .asUint8List());
                                                  //   print(result);
                                                  //   String res1 = result["filePath"];
                                                  // // File saveFile = new File(result.replaceAll("file://", ""));
                                                  //   String res =
                                                  //       res1.replaceAll(
                                                  //           "file://", '');
                                                  //   Map<String, String> map =
                                                  //       new Map();

                                                  //   HttpHelper.upLoadSignImage(
                                                  //       res, (data) {
                                                  //     //loadpage.close();
                                                  //     print('data');
                                                  //     if (data.containsKey(
                                                  //         'code')) {
                                                  //       // Toast.show(data['msg'],
                                                  //       //     context);
                                                  //     } else {}
                                                  //   }, params: map);
                                                  //   // Fluttertoast.showToast(
                                                  //   //   msg: '已保存到相册',
                                                  //   //   toastLength: Toast.LENGTH_SHORT,
                                                  //   //   gravity: ToastGravity.CENTER,
                                                  //   // );
                                                  // }
                                                  SharedPreferences pref =
                                                      await SharedPreferences
                                                          .getInstance();
                                                  // pref.setString(
                                                  //     'islogin',
                                                  //     '1');
                                                  pref.setString('role', "1");
                                                  // Navigator.pushNamed(context, 'blue');
                                                  Navigator.of(context).push(
                                                      new MaterialPageRoute(
                                                          builder: (_) {
                                                    return new LoginPage('1');
                                                  }));
                                                },
                                                color: Colours.app_main,
                                              ),
                                            ),
                                          ),
                                        ))),
                                  )),
                              Positioned(
                                  top: 330,
                                  left: 30,
                                  right: 30,

                                  // child:
                                  // Center(
                                  child: new Container(
                                      // color: Color.fromRGBO(255, 204, 48, 1),
                                      height: 50,
                                      // width: double.infinity,
                                      child: Padding(
                                          padding: new EdgeInsets.fromLTRB(
                                              0, 0, 0, 0),
                                          child: Center(
                                              child: SizedBox(
                                                  width: double.infinity,
                                                  child: new ClipRRect(
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              25),
                                                      child: Align(
                                                          alignment:
                                                              Alignment.center,
                                                          child: new Container(
                                                              child: new Material(
                                                                  //INK可以实现装饰容器
                                                                  child: new Ink(
                                                            //用ink圆角矩形
                                                            // color: Colors.red,
                                                            decoration:
                                                                new BoxDecoration(
                                                              //背景
                                                              color:
                                                                  Colors.white,
                                                              //设置四周圆角 角度
                                                              borderRadius: BorderRadius
                                                                  .all(Radius
                                                                      .circular(
                                                                          25.0)),
                                                              //设置四周边框
                                                              border: new Border
                                                                      .all(
                                                                  width: 1,
                                                                  color: Colours
                                                                      .app_main),
                                                            ),
                                                            child: new InkWell(
                                                                //圆角设置,给水波纹也设置同样的圆角
                                                                //如果这里不设置就会出现矩形的水波纹效果
                                                                borderRadius:
                                                                    new BorderRadius
                                                                            .circular(
                                                                        25.0),
                                                                //设置点击事件回调
                                                                onTap:
                                                                    () async {
                                                                  SharedPreferences
                                                                      pref =
                                                                      await SharedPreferences
                                                                          .getInstance();
                                                                  // pref.setString(
                                                                  //     'islogin',
                                                                  //     '1');
                                                                  pref.setString(
                                                                      'role',
                                                                      "0");
                                                                  // Navigator.of(
                                                                  //         context)
                                                                  //     .pushAndRemoveUntil(
                                                                  //         new MaterialPageRoute(
                                                                  //             builder: (context) =>
                                                                  //                 new MyApp()),
                                                                  //         (route) =>
                                                                  //             route ==
                                                                  //             null);
                                                                  Navigator.of(
                                                                          context)
                                                                      .push(new MaterialPageRoute(
                                                                          builder:
                                                                              (_) {
                                                                    return new LoginPage(
                                                                        '0');
                                                                  }));
                                                                },
                                                                child:
                                                                    Container(
                                                                  //设置 child 居中
                                                                  alignment:
                                                                      Alignment(
                                                                          0, 0),
                                                                  height: 50,
                                                                  width: double
                                                                      .infinity,
                                                                  child: Text(
                                                                    "我是车商/经纪人",
                                                                    style: TextStyle(
                                                                        color: Colours
                                                                            .app_main,
                                                                        fontSize:
                                                                            18),
                                                                  ),
                                                                )),

                                                            // child: new RaisedButton(
                                                            //   child: Text('申请补考'),
                                                            //   onPressed: () {},
                                                            // ),
                                                          )))))))))),
                              Positioned(
                                bottom: 0,
                                left: 0,
                                right: 0,
                                child: Container(
                                  height: 60,
                                  // child: Image.asset(
                                  //   'resource/images/user/back2.png',
                                  //   fit: BoxFit.fill,
                                  // ),
                                ),
                              )
                            ])))));
  }
}
